package IO流.缓冲流.练习;

import java.io.*;
import java.util.Collection;
import java.util.TreeMap;

public class 恢复csb {
    public static void main(String[] args) throws IOException {
        //1.创建出师表的缓冲流对象
        BufferedReader br=new BufferedReader(new FileReader("F\\csb.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("F\\copy.txt"));
        //2.获取每一行数据并放入一个map集合
        TreeMap<Integer,String> map=new TreeMap<>();
        String str;
        while ((str= br.readLine())!=null){
            //获取键
            int key = Integer.parseInt(str.substring(0,1));
            String value = str.substring(2);
            map.put(key,value);
        }
        //3.写入文件
        Collection<String> values = map.values();
        for (String value : values) {
            bw.write(value);
            //进行换行
            bw.newLine();
        }
        //4.释放资源
        br.close();
        bw.close();
    }
}
